package org.breathe.protocal.decode;

import io.netty.buffer.ByteBuf;
import lombok.Getter;
import org.breathe.protocal.Resp;

import java.util.Arrays;

/**
 * @author: breathe
 * @createTime: 2025-05-12
 */
@Getter
public class RespArray extends Resp {
    private final Resp[] content;
    public RespArray(Resp[] content) {
        this.content = content;
    }
    @Override
    public void encode(Resp resp, ByteBuf buffer) {
        buffer.writeByte('*');
        buffer.writeBytes(Integer.toString(content.length).getBytes());
        buffer.writeBytes(CRLF);
        for (Resp r : content) {
            r.encode(r, buffer);
        }
    }

    @Override
    public String toString() {
        return "RespArray{" +
                "content=" + Arrays.toString(content) +
                '}';
    }
}
